package com.imut.oa.controller.user;


import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.pojo.dto.CommonUserPageQueryDTO;
import com.imut.oa.pojo.dto.ExpenseSubmitDTO;
import com.imut.oa.service.ExpenseService;
import com.imut.oa.util.ThreadLoaclUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/expense")
@Slf4j
@Tag(name = "员工报销")
public class UserExpenseController {
    @Autowired
    private ExpenseService expenseService;

    /**
     * 提交报销申请
     * @param expenseSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @Operation(summary = "提交报销申请")
    public BaseResponse<Void> submitExpense(@RequestBody ExpenseSubmitDTO expenseSubmitDTO) {
        log.info("用户提交报销申请：{}", expenseSubmitDTO);
        expenseService.submitExpense(expenseSubmitDTO);
        return ResultUtils.success(null, "提交成功");
    }



    @GetMapping ("/history")
    @Operation(summary = "获取报销历史记录")
    public BaseResponse<?> getLeaveHistory(@RequestParam("currentPage") int currentPage) {
        log.info("获取第 {} 页的报销历史记录", currentPage);
        CommonUserPageQueryDTO queryDTO = new CommonUserPageQueryDTO();
        queryDTO.setPage(currentPage);
        // 假设每页大小固定为 10
        queryDTO.setPageSize(5);
        // 获取当前用户 ID
        Long currentId = ThreadLoaclUtil.getCurrentId();
        queryDTO.setEmployeeId(currentId); // 假设 LeavePageQueryDTO 中有 employeeId 字段
        return ResultUtils.success(expenseService.getExpenseHistory(queryDTO));
    }
//
//    public BaseResponse<Void> cancelExpense(@PathVariable Long expenseId) {
//        expenseService.cancelExpense(expenseId);
//        return ResultUtils.success();
//    }

    @PostMapping("/cancel")
    @Operation(summary = "撤销报销申请")
    public BaseResponse<String> cancelLeave(@RequestParam("expenseId") Long expenseId) {
        log.info("用户撤销请假申请，请假ID：{}", expenseId);
        expenseService.cancelLeave(expenseId);
        return ResultUtils.success("撤销成功", "撤销成功");
    }
}
